package academic.emailClient.control.listeners;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;

import academic.emailClient.model.EmailClientModel;
import academic.emailClient.model.entities.Filter;
import academic.emailClient.view.EmailClientViewInterface;
import academic.emailClient.view.VelocityTemplate;

public class ManageFiltersComboBoxChangedListener implements ItemListener {
	EmailClientViewInterface view;
	EmailClientModel model;
	VelocityTemplate emailDemo;
	
	/**
	 * TemplatesChangedListener Constructor
	 * @throws Exception 
	 */
	
	public ManageFiltersComboBoxChangedListener(EmailClientViewInterface view, EmailClientModel model) throws Exception{
		this.model = model;
		this.view = view;
		emailDemo = new VelocityTemplate();
	}
	
	/**
	 * Handle Manage Filters Combo Box item Changed event
	 */
	@Override
	public void itemStateChanged(ItemEvent e) {
		 if (e.getStateChange() == ItemEvent.SELECTED) {
					String string = e.getItem().toString();
					HashMap<String, String> paths=model.getAllSubfoldersPaths();
					view.setManagerFiltersSubfoldersPath(paths);
					ArrayList<Filter> filters = model.getFilters();
					view.updateManageFiltersField(string, paths, filters);				
		 }
	}

}
